from enum import Enum
from typing import Optional, List, Dict, Any, Union
from pydantic import BaseModel
from app.schemas.metrics_schema import Chart
from app.schemas.facenet_base_schema import TaskStatus

# THGAD算法的输入参数
class THGADInputParams(BaseModel):
    graph_sequence: List[Dict[str, Any]]  # 时序异构图序列
    window_size: int = 5  # 时间窗口大小
    contamination: float = 0.1  # 异常比例

# THGAD算法的异常节点结果
class AnomalyResult(BaseModel):
    node_id: Any  # 节点ID
    anomaly_score: float  # 异常分数
    node_type: str  # 节点类型

# THGAD算法的输出参数
class THGADOutputParams(BaseModel):
    anomalies: List[AnomalyResult]  # 检测到的异常节点列表
    algorithm: str = "THGAD"  # 算法名称
    parameters: Dict[str, Any]  # 算法参数

# 输入参数
class InputParams(BaseModel):
    thgad_params: Optional[THGADInputParams] = None

# 输出参数
class OutputParams(BaseModel):
    thgad_results: Optional[THGADOutputParams] = None

# 算法请求
class AlgorithmRequest(BaseModel):
    task_id: str
    task_callback_url: Optional[str] = None
    input_params: InputParams

# 算法中间响应
class AlgorithmMiddleResponse(BaseModel):
    task_id: str
    task_callback_url: str
    task_status: TaskStatus
    task_progress: int = 0
    task_logs: Optional[str] = None
    
    input_params: InputParams
    error_message: Optional[str] = None
    
    metrics: List[Chart] = []

# 算法最终响应
class AlgorithmResponse(BaseModel):
    task_id: str
    task_callback_url: Optional[str] = None
    task_status: TaskStatus
    task_progress: int = 100
    task_logs: Optional[str] = None
    
    error_message: Optional[str] = None
    
    output_params: OutputParams
    
    metrics: List[Chart] = [] 